import request from '@/utils/request';
import domain from '@/utils/domain';

// 全局快捷入口
export function getUserGlobalMenu(data: any) {
    return request({
        url: '/scrm-api/console/login-api/login/user-function-common',
        method: 'post',
        data
    });
}

//抽奖详情
export function luckcyInfo(data: any) {
    return request({
        url: '/scrm-api/console/channel/activity-info',
        method: 'post',
        data
    });
}
// +++++++++++++++++++++++++++++ 标签 +++++++++++++++++++++++++++++++

//  获取标签组列表
export function getTagsList(data: any) {
    return request({
        url: '/scrm-api/console/content/tag/group-list',
        method: 'get',
        params: data
    });
}
//新增标签组
export function addTags(data: any) {
    return request({
        url: '/scrm-api/console/content/tag/group-add',
        method: 'post',
        data: data
    });
}
//  更新标签组
export function EditTags(data: any) {
    return request({
        url: '/scrm-api/console/content/tag/group-put',
        method: 'post',
        data
    });
}

//  删除标签组
export function delteTags(data: any) {
    return request({
        url: '/scrm-api/console/content/tag/group-del',
        method: 'post',
        data
    });
}
//  获取标签列表
export function getTagList(data: any) {
    return request({
        url: '/scrm-api/console/content/tag/tag-list',
        method: 'get'
    });
}
//批量添加标签
/**
 * type
 * tag_ids
 * is_total
 * content_ids
 * */
export function batchTagAdd(data: any, noNeedLoading = false) {
    return request({
        url: '/scrm-api/console/content/tag/content-tag-batch-add',
        method: 'post',
        data,
        noNeedLoading
    });
}

export function batchTagAdd1(data: any) {
    return request({
        url: '/scrm-api/console/content/tag/content-tag-batch-add',
        method: 'post',
        data,
        noNeedLoading: true
    });
}
//批量删除标签
/**
 * type
 * tag_ids
 * is_total
 * content_ids
 * */
export function batchTagDel(data: any, noNeedLoading = false) {
    return request({
        url: '/scrm-api/console/content/tag/content-tag-batch-del',
        method: 'post',
        data,
        noNeedLoading
    });
}
export function batchTagDel1(data: any) {
    return request({
        url: '/scrm-api/console/content/tag/content-tag-batch-del',
        method: 'post',
        data,
        noNeedLoading: true
    });
}
// 批量下载
/*
  material_ids
  material_ids
*/
export function batchDownLoad(data: any) {
    return request({
        url: '/scrm-api/console/media/content/batch-download',
        method: 'POST',
        data
    });
}
/**修改标签
 * content_ids
 * @param content_id
 * @param tag_ids
 * @returns
 */
export const editTextTag = (data: any) => {
    return request({
        url: '/scrm-api/console/media/content/text/tag-edit',
        method: 'post',
        data
    });
};
// +++++++++++++++++++++++++++++ 部门员工 +++++++++++++++++++++++++++++++
// 获取部门员工信息
export function getDepartUser(data?: any) {
    return request({
        url: '/scrm-api/console/work/contact/department-user-info',
        method: 'get',
        params: data
    });
}
// +++++++++++++++++++++++++++++ 部门员工1.0 +++++++++++++++++++++++++++++++
// 获取部门员工信息
export function getDepartUserInfo(data?: any) {
    return request({
        url: '/scrm-api/console/work/contact/department-user-info-reception',
        method: 'POST',
        data
    });
}
// 上传文件
export async function uploadFile(data: any) {
    return request({
        url: '/scrm-api/console/media/file/apply-upload-param',
        params: data,
        method: 'get',
        type: 1
    });
}
// 上传阿里云
export async function uploadOss(data: any) {
    return request(data);
}
// +++++++++++++++++++++++++++++ 上传文件及阿里云 +++++++++++++++++++++++++++++++
// 上传文件及阿里云
export async function uploadFile2(data: any, config?: any, noNeedLoading = false) {
    const res: any = await request({
        url: '/scrm-api/console/media/file/apply-upload-param',
        data: data,
        method: 'post',
        noNeedLoading,
        type: 1,
        ...(config ?? {})
    });
    const form = new FormData();
    form.append('key', res.dir);
    form.append('policy', res.policy);
    form.append('OSSAccessKeyId', res.accessid);
    form.append('callback', res.callback);
    form.append('signature', res.signature);
    form.append('expire', res.expire);
    form.append('success_action_status', '200');
    form.append('file', data.file);
    return request({
        url: res.host,
        type: 2,
        oss: true,
        method: 'post',
        timeout: 30000,
        noNeedLoading,
        data: form
    });
}
// +++++++++++++++++++++++++++++++++++++ 图形验证码+++++++++++++++++++++++++++
export function getImageCode(data: any) {
    return request({
        url: `${domain.BASE_API_URL}/scrm-api/console/register/captcha-apply?r=${Math.floor(Math.random() * 100)}`,
        method: 'get',
        type: 0,
        params: data
    });
}

// 获取企业税号
export async function getTaxNumber(data: any) {
    return request({
        url: '/scrm-api/tax/number',
        method: 'POST',
        data
    });
}
// 统计Excel行数
export async function getExcelCount(data: any) {
    return request({
        url: '/scrm-api/console/customer/common/line-count',
        method: 'POST',
        data,
        timeout: 60000
    });
}

// 获取创建人列表
export async function getCreateList(data: any) {
    return request({
        url: '/scrm-api/console/market/create/list',
        method: 'POST',
        data,
        noNeedLoading: data.noNeedLoading ? data.noNeedLoading : false
    });
}

/**
 * 自定义字段列表
 * @params data { type: 1 | 2 | 3 | 4 | 5 | 6 }
 * 类型 1-客户群统计数据概览 2-客户群统计群基础数据 3-客户群数据按员工 4-客户群数据按群聊 5-客户群数据按日期 6-客户群详情数据概览 8 数据总览 9 推广明细按推广链接
 */
export const getCommonCustomFieldList = (data: { type: number }) => {
    return request({
        url: '/scrm-api/console/common/custom-field-list',
        method: 'POST',
        data
    });
};

/**
 * 自定义字段列表保存
 * @params data { type: 1 | 2 | 3 | 4 | 5 | 6, field_config: [ 保存的字段值 ]  }
 * 类型 1-客户群统计数据概览 2-客户群统计群基础数据 3-客户群数据按员工 4-客户群数据按群聊 5-客户群数据按日期 6-客户群详情数据概览
 */
export const saveCommonCustomFieldList = (data: { type: number; field_config: string[] }) => {
    return request({
        url: '/scrm-api/console/common/custom-field-save',
        method: 'POST',
        data
    });
};
